using System.Collections.Generic;
using UnityEngine;

public class PlayerItemDrop : ItemDrop
{
    [Header("Player's drop")]
    [SerializeField] private float chanceToLooseItems;
    [SerializeField] private float chanceToLooseMaterials;

    override public void GenerateDrop()
    {
        // list of equipment
        // foreach item we gonna check if should loose item
        Inventory inventory = Inventory.Instance;
        List<InventoryItem> itemsToUnequip = new();
        List<InventoryItem> materialsToLoose = new();
        foreach (InventoryItem item in inventory.GetEquipmentList())
        {
            if (Random.Range(0f, 100f) <= chanceToLooseItems)
            {
                DropItem(item.data);
                itemsToUnequip.Add(item);
            }
        }
        for (int i = 0; i < itemsToUnequip.Count; i++)
        {
            inventory.UnequipItem(itemsToUnequip[i].data as ItemDataEquipment);
        }
        foreach (InventoryItem item in inventory.GetStashList())
        {
            if (Random.Range(0f, 100f) <= chanceToLooseMaterials)
            {
                DropItem(item.data);
                materialsToLoose.Add(item);
            }
        }
        foreach(InventoryItem item in materialsToLoose)
        {
            inventory.RemoveItem(item.data);
        }
    }
}
